package com.smarthealthring.mm.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;

import com.mob.MobApplication;
import com.mob.MobSDK;
import com.mob.tools.utils.BitmapHelper;
import com.mob.tools.utils.ResHelper;

import java.util.ArrayList;
import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.CustomerLogo;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.onekeyshare.OnekeyShareTheme;
import cn.sharesdk.onekeyshare.OnekeyShareThemeImpl;
import cn.sharesdk.onekeyshare.ShareContentCustomizeCallback;

/**
 * Created by joash on 2018/6/11.
 */

public class OnekeyShare2 extends OnekeyShare{

    private HashMap<String, Object> params = new HashMap();

    public OnekeyShare2() {
        this.params.put("customers", new ArrayList());
        this.params.put("hiddenPlatforms", new HashMap());
    }

    public void setAddress(String address) {
        this.params.put("address", address);
    }

    public void setTitle(String title) {
        this.params.put("title", title);
    }

    public void setTitleUrl(String titleUrl) {
        this.params.put("titleUrl", titleUrl);
    }

    public void setText(String text) {
        this.params.put("text", text);
    }

    public String getText() {
        return this.params.containsKey("text")?String.valueOf(this.params.get("text")):null;
    }

    public void setImagePath(String imagePath) {
        if(!TextUtils.isEmpty(imagePath)) {
            this.params.put("imagePath", imagePath);
        }

    }

    public void setImageUrl(String imageUrl) {
        if(!TextUtils.isEmpty(imageUrl)) {
            this.params.put("imageUrl", imageUrl);
        }

    }

    public void setImageData(Bitmap iamgeData) {
        if(iamgeData != null) {
            this.params.put("imageData", iamgeData);
        }

    }

    public void setUrl(String url) {
        this.params.put("url", url);
    }

    public void setFilePath(String filePath) {
        this.params.put("filePath", filePath);
    }

    public void setComment(String comment) {
        this.params.put("comment", comment);
    }

    public void setSite(String site) {
        this.params.put("site", site);
    }

    public void setSiteUrl(String siteUrl) {
        this.params.put("siteUrl", siteUrl);
    }

    public void setVenueName(String venueName) {
        this.params.put("venueName", venueName);
    }

    public void setVenueDescription(String venueDescription) {
        this.params.put("venueDescription", venueDescription);
    }

    public void setLatitude(float latitude) {
        this.params.put("latitude", Float.valueOf(latitude));
    }

    public void setLongitude(float longitude) {
        this.params.put("longitude", Float.valueOf(longitude));
    }

    public void setSilent(boolean silent) {
        this.params.put("silent", Boolean.valueOf(silent));
    }

    public void setDialogMode(boolean isDialog) {
        this.params.put("dialogMode", Boolean.valueOf(isDialog));
    }

    public void setPlatform(String platform) {
        this.params.put("platform", platform);
    }

    public void setInstallUrl(String installurl) {
        this.params.put("installurl", installurl);
    }

    public void setExecuteUrl(String executeurl) {
        this.params.put("executeurl", executeurl);
    }

    public void setMusicUrl(String musicUrl) {
        this.params.put("musicUrl", musicUrl);
    }

    public void setCallback(PlatformActionListener callback) {
        this.params.put("callback", callback);
    }

    public PlatformActionListener getCallback() {
        return (PlatformActionListener)ResHelper.forceCast(this.params.get("callback"));
    }

    public void setShareContentCustomizeCallback(ShareContentCustomizeCallback callback) {
        this.params.put("customizeCallback", callback);
    }

    public ShareContentCustomizeCallback getShareContentCustomizeCallback() {
        return (ShareContentCustomizeCallback)ResHelper.forceCast(this.params.get("customizeCallback"));
    }

    public void setCustomerLogo(Bitmap logo, String label, View.OnClickListener ocl) {
        CustomerLogo cl = new CustomerLogo();
        cl.logo = logo;
        cl.label = label;
        cl.listener = ocl;
        ArrayList<CustomerLogo> customers = (ArrayList)ResHelper.forceCast(this.params.get("customers"));
        customers.add(cl);
    }

    public void disableSSOWhenAuthorize() {
        this.params.put("disableSSO", Boolean.valueOf(true));
    }

    public void setVideoUrl(String url) {
        this.params.put("url", url);
        this.params.put("shareType", Integer.valueOf(6));
    }

    public void addHiddenPlatform(String platform) {
        HashMap<String, String> hiddenPlatforms = (HashMap)ResHelper.forceCast(this.params.get("hiddenPlatforms"));
        hiddenPlatforms.put(platform, platform);
    }

    public void setViewToShare(View viewToShare) {
        try {
            Bitmap bm = BitmapHelper.captureView(viewToShare, viewToShare.getWidth(), viewToShare.getHeight());
            this.params.put("viewToShare", bm);
        } catch (Throwable var3) {
            var3.printStackTrace();
        }

    }

    public void setImageArray(String[] imageArray) {
        this.params.put("imageArray", imageArray);
    }

    public void setShareToTencentWeiboWhenPerformingQQOrQZoneSharing() {
        this.params.put("isShareTencentWeibo", Boolean.valueOf(true));
    }

    public void setTheme(OnekeyShareTheme theme) {
        this.params.put("theme", Integer.valueOf(theme.getValue()));
    }

    public void show(Context context) {
        HashMap<String, Object> shareParamsMap = new HashMap();
        shareParamsMap.putAll(this.params);
        if(!(context instanceof MobApplication)) {
            MobSDK.init(context.getApplicationContext());
        }

        ShareSDK.logDemoEvent(1, (Platform)null);
        int iTheme = 0;

        try {
            iTheme = ResHelper.parseInt(String.valueOf(shareParamsMap.remove("theme")));
        } catch (Throwable var6) {
            ;
        }

        OnekeyShareTheme theme = OnekeyShareTheme.fromValue(iTheme);
        OnekeyShareThemeImpl themeImpl = theme.getImpl();
        themeImpl.setShareParamsMap(shareParamsMap);
        themeImpl.setDialogMode(shareParamsMap.containsKey("dialogMode")?((Boolean)shareParamsMap.remove("dialogMode")).booleanValue():false);
        themeImpl.setSilent(shareParamsMap.containsKey("silent")?((Boolean)shareParamsMap.remove("silent")).booleanValue():false);
        themeImpl.setCustomerLogos((ArrayList)shareParamsMap.remove("customers"));
        themeImpl.setHiddenPlatforms((HashMap)shareParamsMap.remove("hiddenPlatforms"));
        themeImpl.setPlatformActionListener((PlatformActionListener)shareParamsMap.remove("callback"));
        themeImpl.setShareContentCustomizeCallback((ShareContentCustomizeCallback)shareParamsMap.remove("customizeCallback"));
        if(shareParamsMap.containsKey("disableSSO") && ((Boolean)shareParamsMap.remove("disableSSO")).booleanValue()) {
            themeImpl.disableSSO();
        }

        themeImpl.show(context.getApplicationContext());
    }

    //自己加的
    public void setBitmapToShare(Bitmap bm) {
        try {
            params.put("viewToShare", bm);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
